package com.itheima.service.Impl;

import com.itheima.dao.CheckGroupMapper;
import com.itheima.dao.CheckItemMapper;
import com.itheima.dao.SetmealMapper;
import com.itheima.pojo.CheckGroup;
import com.itheima.pojo.CheckItem;
import com.itheima.pojo.Setmeal;
import com.itheima.service.SetmealService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;

@Service
public class SetmealServiceImpl implements SetmealService {

    @Autowired
    SetmealMapper setmealMapper;
    @Autowired
    CheckGroupMapper checkGroupMapper;
    @Autowired
    CheckItemMapper checkItemMapper;

    /**
     * 获取套餐
     * @return
     */
    public ArrayList<Setmeal> getSetmeal() {

        ArrayList<Setmeal> setmeals = setmealMapper.getSetmeal();

        return setmeals;
    }

    /**
     * 根据id查询套餐详细信息
     * @param id
     * @return
     */
    public Setmeal findById(Integer id) {
        //根据id查询套餐信息
        Setmeal setmeal = setmealMapper.findById(id);
        //根据套餐id查询检查组信息
        ArrayList<CheckGroup> checkGroups = checkGroupMapper.findBySetmealId(id);
        //根据检查组id查询检查项信息
        for (CheckGroup checkGroup : checkGroups) {
            ArrayList<CheckItem> checkItems = checkItemMapper.findByCheckGroupId(checkGroup.getId());
            checkGroup.setCheckItems(checkItems);
        }
        setmeal.setCheckGroups(checkGroups);

        return setmeal;
    }
}
